package proj2501.simple_module;

import java.io.BufferedReader;
import java.io.File;
import java.io.PrintWriter;

import javax.swing.JPanel;

import proj2501.util.UU;

class P004IO extends JPanel {
	private String path1 = "test_2013-11-27.txt";
	private String path2 = "test_2013-11-27_2.txt";
	
	public P004IO() {
//		System.out.println("Constructing P004IO");
//		String separator = System.getProperty("line.separator");
//		System.out.println("line.separator: " + separator);
//		String encoding = System.getProperty("file.encoding");
//		System.out.println("file.encoding: " + encoding);
//		writeText1();
//		writeText2_Shift_JIS();
//		readText1();
//		readText2_Shift_JIS();
//		UU.write(path1, "jasdl;kjflska;jdfklj\nwlekjlkjwekwlejklw");
//		System.out.println(UU.read(path1));
//		File f1 = new File(path1);
//		System.out.println(f1.getAbsolutePath());
		
//		UU.zip("d1", "d1.zip");
		
//		byte[] bytes = UU.getSHA_1("abc".getBytes());
//		String s = DatatypeConverter.printHexBinary(bytes);
//		System.out.println(s);
		UU.printMD5("abc".getBytes());
		UU.printMD5(new File(path1));
	}
	
	public void writeText1() {
		PrintWriter pw = UU.getPrintWriter(path1);
		pw.println("hello, world!");
		pw.println("日本語");
		pw.print("Unix newline ->\n");
		pw.print("Windows newline ->\r\n");
		pw.close();
	}
	
	public void writeText2_Shift_JIS() {
		PrintWriter pw = UU.getPrintWriter(path2, "Shift_JIS");
		pw.println("Shift_JIS?");
		pw.println("hello, world!");
		pw.println("日本語");
		pw.print("Unix newline ->\n");
		pw.print("Windows newline ->\r\n");
		pw.close();
	}
	
	public void readText1() {
		BufferedReader br = UU.getBufferedReader(path1);
		UU.print(br);
	}
	
	public void readText2_Shift_JIS() {
		BufferedReader br = UU.getBufferedReader(path2, "Shift_JIS");
		UU.print(br);
	}
}
